﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.SessionState;
using System.Web.Routing;
using System.Text;
using System.Data;

namespace Htss.Platform.WebApi.Http
{
    public  static class HttpInvoke
    {
        /// <summary>
        /// 启动程序
        /// </summary>
        /// <param name="RequestContext"></param>
        public static void Init(RequestContext RequestContext)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("NameSpace", RequestContext.RouteData.DataTokens["Namespace"] == null ? "" : RequestContext.RouteData.DataTokens["Namespace"].ToString());
            dic.Add("BoxName", RequestContext.RouteData.Values["box"].ToString());
            //
            InvokeBox ibox = new InvokeBox(RequestContext);
            ibox.ActionBox = dic;

            ibox.Invoke();

            //接收执行返回值
            Object result = ibox.ResultObject;
            //当返回结果为null时 则返回的是void类型
            if (result != null)
            {
                if (result.GetType().IsSubclassOf(typeof(ActionResult)))
                {
                    ActionResult actionResult = (ActionResult)result;
                    RequestContext.HttpContext.Response.Write(actionResult.ResultObject);
                }
                else
                {
                    RequestContext.HttpContext.Response.Write(result);
                }
            }
        }
    }
}
